Friend Class EmulatorLog

    Private m_grid(,) As Boolean
    Private m_WidthTrace() As Boolean
    Private m_HeightTrace() As Boolean
    Private m_lastFour(3) As Integer
    Private m_address As Integer = 0
    Private m_width As Short = 0
    Private m_height As Short = 0
    Private m_sixteenbit As Boolean = False

    Friend Sub New(ByVal Address As Integer, ByVal Width As Short, ByVal Height As Short, ByVal SixTeenBit As Boolean)
        m_address = Address
        m_width = Width
        m_height = Height
        Me.m_sixteenbit = SixTeenBit
        ReDim m_grid(m_width - 1, m_height - 1)
        ReDim m_WidthTrace(m_width - 1)
        ReDim m_HeightTrace(m_height - 1)
        For Each pt As Boolean In m_grid
            pt = False
        Next
    End Sub

    Friend Sub Clear()
        For x As Int16 = 0 To m_grid.GetUpperBound(0)
            For y As Int16 = 0 To m_grid.GetUpperBound(1)
                m_grid(x, y) = False
            Next
        Next
    End Sub
    Friend ReadOnly Property Last() As Integer()
        Get
            If Me.m_sixteenbit Then
                Dim f_ret(7) As Integer
                For i As Integer = 0 To 7 Step 2
                    f_ret(i) = m_lastFour(i / 2)
                    f_ret(i + 1) = m_lastFour(i / 2) + 1
                Next
                Return f_ret
            Else
                Return m_lastFour
            End If
        End Get
    End Property
    Friend Sub addRange(ByRef Address() As Integer)
        Dim f_tmpAdr As Integer
        If Not IsNothing(Address) Then
            If Me.m_sixteenbit Then
                For i As Integer = 0 To UBound(Address)
                    Address(i) *= 2
                Next
            End If
            If Address.Length >= 4 Then
                m_lastFour(0) = Address(0)
                m_lastFour(1) = Address(1)
                m_lastFour(2) = Address(2)
                m_lastFour(3) = Address(3)
            End If
            For Each adr As Integer In Address
                If adr >= m_address And adr < (m_address + (m_width * m_height)) Then
                    m_grid((adr - m_address) Mod m_width, (adr - m_address) \ m_height) = True
                    If Me.m_sixteenbit Then
                        f_tmpAdr = adr + 1
                        m_grid(((f_tmpAdr - m_address) Mod m_width), (f_tmpAdr - m_address) \ m_height) = True
                    End If
                End If
            Next
            If Address.Length >= 4 Then
                For Each pt As Boolean In m_HeightTrace
                    pt = False
                Next
                For Each pt As Boolean In m_WidthTrace
                    pt = False
                Next
                For i As Int16 = 0 To 3
                    If Address(i) <> 0 Then
                        m_WidthTrace(((Address(i) - m_address) Mod m_width)) = True
                        m_HeightTrace(((Address(i) - m_address) \ m_height)) = True
                        If Me.m_sixteenbit Then
                            m_WidthTrace(((Address(i) + 1 - m_address) Mod m_width)) = True
                            m_HeightTrace(((Address(i) + 1 - m_address) \ m_height)) = True
                        End If
                    End If
                Next
            End If
        End If
    End Sub

    Friend ReadOnly Property LiveWidth() As Boolean()
        Get
            Return m_WidthTrace
        End Get
    End Property
    Friend ReadOnly Property LiveHeight() As Boolean()
        Get
            Return m_HeightTrace
        End Get
    End Property
    Friend ReadOnly Property Grid() As Boolean(,)
        Get
            Return m_grid
        End Get
    End Property

    Friend ReadOnly Property Address() As Integer
        Get
            Return m_address
        End Get
    End Property
End Class
